Handling large integers in python [migrated]

Posted by Sushma Palimar on Programmers See other posts from Programmers or by Sushma Palimar
Published on 2013-10-22T11:02:43Z Indexed on 2013/10/22 16:02 UTC
Read the original article Hit count: 169

I had written a program in python to find b such that a prime number p divides b^2-8. The range for b is [1, (p+1)/2].

For small integers it works, say only up to 7 digits. But not for large integers, say for p = 140737471578113. I get the error message

    for i in range (2,p1,1):
MemoryError

I wrote the program as

#!/usr/bin/python3
p=long(raw_input('enter the prime number:'))
p1=long((p+1)/2)
for   i in range (2,p1,1):
    s = long((i*i)-8)
    if (s%p==0):
        print i

© Programmers or respective owner

Related posts about programming-practices

Related posts about python